package com.thread;

public class Student {
    private String name;
    private String age;
    private boolean flag;

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
    public synchronized void SetStudent(String name,String age)
    {
        if(this.flag==true)
        {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.name=name;
        this.age=age;
        this.flag=true;
        this.notify();
    }

    public synchronized void GetStudent()
    {
        if (this.flag==false)
        {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName()+"--"+this.name+":"+this.age);
        this.flag=false;
        this.notify();
    }
}
